package KIMS;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Index {

	private static final String[] indexnames = { "销售利润率", "营业利润率", "税前利润率",
			"净利润率", "资产报酬率", "资产报酬率", "权益报酬率", "总资产周转率", "应收帐款周转率", "存货周转率",
			"资产负债率", "负债与所有者权益比率", "负债与有形净资产比率", "流动比率", "速冻比率", "现金比率",
			"利息保障倍数", "销售增长率", "主营业务利润增长率", "资本增殖率", "现金到期债务比率", "流入流出现金比率",
			"贷款到期清偿率", "应付帐款到期清偿率", "存货款比率" };

	private double[][] sample;// 样本矩阵
	private double[][] standard;// 标准化矩阵
	private double[][] rc;// 相关系数矩阵,一个实对称矩阵,运算的最终结果是对角线存放特征值
	private int rclength;
	private double[][] rctemp;// 删减后剩余指标的相关系数矩阵
	private double[][] ortho;// 正交矩阵，最终存放特征向量
	private double[][] unitmatrix;// 单位矩阵，仅作为雅可比计算方法的第一次参数，雅克比计算方法中暂存当前所有正交矩阵的乘积矩阵。
	private double characteristic;//特征值总和
	private double eps=0.000001;// 收敛精度
	private double delcontribute;// 被删指标的累计贡献值
	private double defcontr;// 指定的贡献率
	private List<String> remainindex = new ArrayList<String>();// 剩余的指标名称列表
	private List<String> delindex = new ArrayList<String>();// 删除的指标名称列表

	/**
	 * 构造方法
	 */
	public Index() {
		remainindex = Arrays.asList(indexnames);
		rc = new double[sample[0].length][sample[0].length];
		rctemp=new double[sample[0].length][sample[0].length];
		rclength=rc.length;
		unitmatrix = new double[rc.length][rc.length];
		for (int i = 0; i < rc.length; i++)
			for (int j = 0; j < rc.length; j++)
				if (i == j)
					unitmatrix[i][j] = 1;
	}

	/**
	 * 删除指标
	 * @param num 需要删除的指标编号
	 */
	public void delIndex(int num) {
		delindex.add(remainindex.remove(num));
		rc = new double[rclength - 1][rclength - 1];
		/* 删除某个指标后的新的相关系数矩阵 */
		for (int m = 0, i = 0; i < rclength; m++, i++) {
			if (i == num)
				if (num == rclength - 1)
					break;
				else
					i++;
			for (int n = 0, j = 0; j < rclength; n++, j++) {
				if (j == num)
					if (num == rclength - 1)
						break;
					else
						j++;
				rc[m][n] = rctemp[i][j];
			}
		}
		
		rclength=rclength--;
		rctemp=new double[rclength][rclength];
	}

	/**
	 * 复制相关系数矩阵，防止在运算过程中丢失数据。
	 * 
	 * @param rc 相关系数矩阵
	 */
	public void copyOrtho(double[][] rc) {
		for (int i = 0; i < rc.length; i++)
			System.arraycopy(rc[i], 0, rctemp[i], 0, rc[i].length);
	}

	/*getset方法*/
	
	public double[][] getSample() {
		return sample;
	}

	public double getDelcontribute() {
		return delcontribute;
	}

	public void setDelcontribute(double delcontribute) {
		this.delcontribute = delcontribute;
	}

	public double getRemaincontr() {
		return 1-delcontribute/characteristic;
	}

	public void setSample(double[][] sample) {
		this.sample = sample;
	}
	
	public double getCharacteristic() {
		return characteristic;
	}

	public void setCharacteristic(double characteristic) {
		this.characteristic = characteristic;
	}


	public double[][] getStandard() {
		return standard;
	}

	public void setStandard(double[][] standard) {
		this.standard = standard;
	}

	public double[][] getRc() {
		return rc;
	}

	public void setRc(double[][] rc) {
		this.rc = rc;
	}

	public double getEps() {
		return eps;
	}

	public void setEps(double eps) {
		this.eps = eps;
	}

	public double getDefcontr() {
		return defcontr;
	}

	public void setDefcontr(double defcontr) {
		this.defcontr = defcontr;
	}

	public double[][] getOrtho() {
		return ortho;
	}

	public void setOrtho(double[][] ortho) {
		this.ortho = ortho;
	}

	public double[][] getUnitmatrix() {
		return unitmatrix;
	}

	public void setUnitmatrix(double[][] unitmatrix) {
		this.unitmatrix = unitmatrix;
	}

	public List<String> getRemainindex() {
		return remainindex;
	}

	public List<String> getDelindex() {
		return delindex;
	}

	public String[] getIndexnames() {
		return indexnames;
	}

}
